-Distortion of Images in Xi-
At first reload the example image into an array called image Note that all functions on this page are capable of handling RGB or colormap based images. This means that in the following the variable image can be a MxNx3 dimensional array (in case of RGB) or MxN dimensional array (for colormap based images). In the latter the array is treated as an ordinary matrix. The transformations takes the matrix into consideration only. No colormap is used.
( 1)>image=read_targa("mailbox.tga");For magnifying or shrinking of images Xi's standard array resize function can be utilized. Especially for RGB or colormap based images fast resize function do exist called image_resize. The following command line
( 2)>next=image_resize(image,600,500,\linear);magnifies the image to 600 rows and 500 columns using a bilinear interpolation method. Without the parameter linear the command image_resize only changes the pixel size without doing any interpolation.
An image can be rotated with the command rotate whereby an anti-aliasing function reduces artefacts. This feature can be deactivated with the parameter noantialiase.
( 3)>rot=rotate(image,45);The designated angle must be given in degrees.
A similar processing method is the shearing of images (in this case with no antialiasing):
( 4)>sh=shear(image,45,\noantialiase);
90,180,270 degree rotations can be performed more efficiently by using the flip command. Furthermore top for button and left for right operations are availablale.
( 5)>f90=flip(image,\r90); ( 6)>f180=flip(image,\r180); ( 7)>tb=flip(image,\topbottom);
To add a border to an image the image_pad command can be used. The parameters top, bottom, left and right set the border at the specific side. In case of RGB images the parameter color (an array with 3 entries) can be given to determine the color of the border. With colormaps the parameter value sets the border value.
( 8)>bo=image_pad(image,\top=3,\left=4,\color={150,0,150}); ( 9)> /* now let's try it with a colormap based image */ ( 10)>colorBased=rgb2map(color_reduce(image,\colors=256)); ( 11)>bq=image_pad(colorBased,\right=4,\value=72);
Dithering is possible with the dither function. Necessary parameters are r,g, and b which describe the resolution (in bits) of the RGB cube in R, G and B direction.
( 12)>di=dither(image,2,4,4);The result will be an image of at least 2^10 different colors. As an exception from the rule mentioned above this funtion is only capable handling RGB images.
A more complex non local pixel transformation is the convolution method. Convolution means replacing each pixel with a weighted average of the nearby pixels. The weights and the area to average are determined by the convolution matrix. The parameter rescale avoids overflows during the convolution.
( 12)>kernel=double({ {1,2,1},{2,4,2},{1,2,1} }); /* convolution matrix */ ( 14)>kernel/=total(kernel); /* normalized matrix */ ( 15)>co=convol(colorBased, kernel, \rescale);In the case of RGB the convolution matrix has to be from the type double kernel[n,n,3];. For example the convolution matrix for the color red corresponds to the matrix kernel[*,*,0] and so on.
A special kind of convolution transformation is the smooth function. The parameter range determines the rows (eqn. columns) of the convolution matrix. Each entry of the convolution matrix is equal to 1/range^2;
( 16)>sm=smooth(image,\range=5,\rescale);